﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using BusinessLayer.Tables;
using System.Data;
using System.Collections.Generic;
using Data;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DataService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class DataService : System.Web.Services.WebService
{
    public DataService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    #region Fields
    InterPos pos;
    #endregion

    [WebMethod]
    public DataSet DepoList()
    {
        Db_Depo depo = new Db_Depo();
        DataTable dt = depo.GetAllRecord_Datatable("depo_id", "depo_adi");
        return dt.DataSet;
    }

    [WebMethod]
    public DataSet PosList(int DepoId)
    {
        Db_Poslar pos = new Db_Poslar();
        List<string> select = new List<string>();
        select.Add("cash_id");
        select.Add("cash_adi");
        select.Add("cash_tip");
        select.Add("cash_stok_exp");
        select.Add("cash_sale_imp");
        select.Add("cash_msg");
        select.Add("cash_fatseri");
        select.Add("cash_nakitkasa");
        select.Add("cash_port_no");
        select.Add("cash_yardimci_prg");
        DataTable dt = pos.GetAllRecord_Datatable(select.ToArray(), "cash_depo_id = " + DepoId.ToString());
        return dt.DataSet;
    }

    [WebMethod]
    public DataSet PosList2(int DepoId, int CashTip)
    {
        Db_Poslar pos = new Db_Poslar();
        List<string> select = new List<string>();
        select.Add("cash_id");
        select.Add("cash_adi");
        select.Add("cash_tip");
        select.Add("cash_stok_exp");
        select.Add("cash_sale_imp");
        select.Add("cash_msg");
        select.Add("cash_fatseri");
        select.Add("cash_nakitkasa");
        select.Add("cash_port_no");
        select.Add("cash_yardimci_prg");
        DataTable dt = pos.GetAllRecord_Datatable(select.ToArray(), "cash_depo_id = " + DepoId.ToString(), "cash_tip=" + CashTip.ToString());
        return dt.DataSet;
    }

    [WebMethod]
    public DataSet MusteriList()
    {
        Db_Musteri musteri = new Db_Musteri();
        List<string> select = new List<string>();
        select.Add("rec_id");
        select.Add("musteri_kod");
        select.Add("musteri_adi");
        select.Add("(is_mahalle + ' Mah.' + is_cadde + ' Cd.' + is_sokak + ' Sk. No:' + cast(is_no as varchar) + is_il + ' / ' + is_ilce) as adres");
        select.Add("vergi_dairesi");
        select.Add("vergi_numarasi");
        select.Add("'0' as Disc");

        List<string> where = new List<string>();

        DataTable dt = musteri.GetAllRecord_Datatable(select.ToArray(), where.ToArray(), "musteri_kod asc");
        return dt.DataSet;
    }

    [WebMethod]
    public byte[] PromosyonGonder()
    {
        pos = new InterPos();
        return pos.PromosyonDosyasi();
    }

    [WebMethod]
    public byte[] ReyonDatOlustur()
    {
        pos = new InterPos();
        return pos.CreateReyonDAT();
    }

    [WebMethod]
    public void HareketFile(DataSet ds)
    {
        pos = new InterPos();
        pos.HareketFileSave(ds);
    }

    [WebMethod]
    public byte[] InterPos_Cari()
    {
        pos = new InterPos();
        DataTable dt = pos.CariCek();
        byte[] returns = pos.InterPOS_Cari_Exp(dt);
        return returns;
    }

    [WebMethod]
    public byte[] InterPosUrunDat()
    {
        pos = new InterPos();
        return pos.URUNDAT();
    }

    [WebMethod]
    public DataSet DepoPos(string depono)
    {
        pos = new InterPos();
        return pos.DepoPos(depono).DataSet;
    }

    public DataSet BackOfficeFiyatlar(string Depo, int fiyatno)
    {
        string programtip = ConfigurationSettings.AppSettings["BackOfficeType"];
        string backoffice = ConfigurationSettings.AppSettings["BackOfficeConnection"];

        string strSql = "";

        switch (programtip)
        {
            case "V11":
                strSql = "SELECT sto_RECno, sto_isim, dbo.fn_PosFiyat(" + Depo + ", sto_kod) AS fiyat   FROM         STOK  WHERE     (dbo.fn_PosFiyat(" + Depo + ", sto_kod) > 0) ORDER BY sto_RECno";
                break;
            case "V12":
                strSql = "SELECT  sto_RECno, sto_isim, dbo.fn_StokSatisFiyati(sto_kod, " + fiyatno.ToString() + ", " + Depo + ") AS fiyat FROM         STOKLAR WHERE (dbo.fn_StokSatisFiyati(sto_kod, " + fiyatno.ToString() + ", " + Depo + ") > 0) ORDER BY sto_RECno";
                break;
            default:
                break;
        }
        SqlConnection cn = new SqlConnection(backoffice);
        cn.Open();
        SqlDataAdapter adp = new SqlDataAdapter(strSql, cn);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        cn.Close();
        return ds;
    }

}

